#ifndef DATABASEHELPER_H
#define DATABASEHELPER_H
#include <QString>
#include <QSqlDatabase>
#include "employee.h"
#include "employeeincome.h"
#include "salonincome.h"
#include "salaryexpend.h"
#include "expenseitems.h"
class Databasehelper
{
private:
    QSqlDatabase db;
public:
    // Logcat tag
    static const QString LOG;

    // Database Version
    static const int DATABASE_VERSION;

    // Database Name
    static const QString DATABASE_NAME;
    static const QString USER;
    static const QString PASSWORD;
    static const QString HOST;

    // Table Names
    static const QString TABLE_EMPLOYEES;
    static const QString TABLE_EMPLOYEE_INCOMES;
    static const QString TABLE_SALON_INCOMES;
    static const QString TABLE_EXPEND_SALARY;
    static const QString TABLE_EXPENSE_ITEMS;

    // Common column names
    static const QString FIELD_ID;
    static const QString FIELD_CREATED_AT;
    static const QString FIELD_MODIFIED_AT;

    // EMPLOYEES Table - column names
    static const QString FIELD_EMPLOYEES_NAME;
    static const QString FIELD_EMPLOYEES_PHONE;
    static const QString FIELD_EMPLOYEES_SALARY_RATE;
    static const QString FIELD_EMPLOYEES_CASH_RATE;
    static const QString FIELD_EMPLOYEES_WORKING_STATUS;
    static const QString FIELD_EMPLOYEES_PAID_AT;

    // EMPLOYEE_INCOMES Table - column names
    static const QString FIELD_EMPLOYEE_INCOMES_EMPLOYEE_ID;
    static const QString FIELD_EMPLOYEE_INCOMES_SALARY;
    static const QString FIELD_EMPLOYEE_INCOMES_TIP;

    // SALON_INCOMES table - column names
    static const QString FIELD_SALON_INCOMES_CASH;
    static const QString FIELD_SALON_INCOMES_CREDIT;
    static const QString FIELD_SALON_INCOMES_TOTAL;
    static const QString FIELD_SALON_INCOMES_GIFT_OUT;
    static const QString FIELD_SALON_INCOMES_GIFT_IN;

    // EXPEND_SALARY table - column names
    static const QString FIELD_EXPEND_SALARY_EMPLOYEE_ID;
    static const QString FIELD_EXPEND_SALARY_SALARY_RATE;
    static const QString FIELD_EXPEND_SALARY_CASH_RATE;
    static const QString FIELD_EXPEND_SALARY_CASH;
    static const QString FIELD_EXPEND_SALARY_CHECK;
    static const QString FIELD_EXPEND_SALARY_TIP;
    static const QString FIELD_EXPEND_SALARY_START_AT;
    static const QString FIELD_EXPEND_SALARY_END_AT;

    // EXPEND_ITEMS table - column names
    static const QString FIELD_EXPEND_ITEMS_NAME;
    static const QString FIELD_EXPEND_ITEMS_COLOR;
    static const QString FIELD_EXPEND_ITEMS_ICON;



    Databasehelper();
    bool openConnection();
    void closeConnection();

    // Employee table operators
    int createEmployee(Employee *employee);
    bool updateEmployee(Employee *employee);
    QLinkedList<Employee*>* selectEmployee(QString condition);

    //Employee incomes table operators
    int createEmployeeIncomes(EmployeeIncome* empl_incomes);
    bool updateEmployeeIncomes(QStandardItemModel* model, QProgressDialog *progressDialog);
    QLinkedList<EmployeeIncome*>* selectEmployeeIncomes(const QDate dateIncome);
    QLinkedList<EmployeeIncome*>* selectEmployeeIncomes(QString condition);

    //Salon income table operators
    bool updateSalonIncomes(QStandardItemModel* model, QString note, QProgressDialog *progressDialog);

    //Salary paid
    QDate getLastPaidDate();
    bool updatePayroll(QStandardItemModel *model, QProgressDialog *progressDialog);
    QLinkedList<SalaryExpend*>* selectPayrollView();

    //expense items
    int updateExpenseItems(ExpenseItems *expense_items);
    QLinkedList<ExpenseItems*>* selectExpenseItems();
};

#endif // DATABASEHELPER_H
